package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-03-17 23:44
 */
public class Q1160 {
    public int countCharacters(String[] words, String chars) {
        int res = 0;
        for (String word : words) {
            int[] cns = new int[26];
            for (int i = 0; i < chars.length(); i++) {
                cns[chars.charAt(i) - 'a']++;
            }

            int i;
            for (i = 0; i < word.length(); i++) {
                cns[word.charAt(i) - 'a']--;
                if(cns[word.charAt(i) - 'a'] < 0) {
                    break;
                }
            }
            if(i == word.length()) {
                res += word.length();
            }
        }

        return res;
    }
}
